import web
from subprocess import PIPE, Popen

urls = (
    '/', 'index',
    '/code', 'code',
)
app = web.application(urls, globals())
render = web.template.render('')
class index:
    def GET(self):
        return render.index1()

class code:
    def POST(self):
        code = str(web.data(), encoding="utf-8")
        file = open(r"code.py", "w", encoding='utf-8')
        file.write(code)
        file.close()
        p = Popen(r"python code.py")
        # p = Popen(r"python code.py", shell=True, stdout=PIPE, stderr=PIPE)
        # stdout, stderr = p.communicate()
        # if len(stderr)>0:
        #     return stderr
        # else:
        #     return stdout

if __name__ == "__main__":
    app.run()
